/*
 * Copyright 2010 Mttang.com All right reserved. This software is the
 * confidential and proprietary information of Mttang.com ("Confidential
 * Information"). You shall not disclose such Confidential Information and shall
 * use it only in accordance with the terms of the license agreement you entered
 * into with Mttang.com.
 */
package com.mttang.sys.integration.dao.support;

import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.mttang.sys.dto.MenuDTO;
import com.mttang.sys.integration.dao.MenuDAO;

/**
 * 类MenuDAOImpl.java的实现描述：TODO 类实现描述 
 * @author acc 2010-6-1 上午11:16:08
 */
public class MenuDAOImpl extends SqlMapClientDaoSupport implements MenuDAO{

    private Log logger = LogFactory.getLog(getClass());
    /* (non-Javadoc)
     * @see com.mttang.sys.integration.dao.MenuDAO#delete(com.mttang.sys.dto.MenuDTO)
     */
    @Override
    public void delete(MenuDTO dto) {
        // TODO Auto-generated method stub
        if (logger.isInfoEnabled()) {
            logger.info("---MenuDAOImpl---delete");
        }
        getSqlMapClientTemplate().delete("SYS.deleteMenu", dto);
    }

    /* (non-Javadoc)
     * @see com.mttang.sys.integration.dao.MenuDAO#findById(java.lang.Integer)
     */
    @Override
    public MenuDTO findById(Integer id) {
        // TODO Auto-generated method stub
        if (logger.isInfoEnabled()) {
            logger.info("---MenuDAOImpl---findById");
        }
        return (MenuDTO)getSqlMapClientTemplate().queryForObject("SYS.selectMenuById", id);
    }

    /* (non-Javadoc)
     * @see com.mttang.sys.integration.dao.MenuDAO#findCount(java.util.Map)
     */
    @Override
    public Long findCount(Map<String, Object> param) {
        // TODO Auto-generated method stub
        if (logger.isInfoEnabled()) {
            logger.info("---MenuDAOImpl---findCount");
        }
        return null;
    }

    /* (non-Javadoc)
     * @see com.mttang.sys.integration.dao.MenuDAO#findUser(java.util.Map)
     */
    @SuppressWarnings("unchecked")
    @Override
    public List<MenuDTO> findMenu(Map<String, Object> param) {
        // TODO Auto-generated method stub
        if (logger.isInfoEnabled()) {
            logger.info("---MenuDAOImpl---findMenu");
        }
        return getSqlMapClientTemplate().queryForList("SYS.selectMenu", param);
    }
    
    @SuppressWarnings("unchecked")
    @Override
    public List<MenuDTO> findMenuTop(Map<String, Object> param) {
        // TODO Auto-generated method stub
        if (logger.isInfoEnabled()) {
            logger.info("---MenuDAOImpl---findMenuTop");
        }
        if((String.valueOf(param.get("roleId")).split(",").length)>1){
            String[]  ss=String.valueOf(param.get("roleId")).substring(1, String.valueOf(param.get("roleId")).length()-1).split(",");
            param.put("ss", ss);
            }else{
                String[]  ss=String.valueOf(param.get("roleId")).split(",");
                param.put("ss", ss);
            }
        return getSqlMapClientTemplate().queryForList("SYS.selectMenuTop", param);
    }
    @SuppressWarnings("unchecked")
    public List<MenuDTO> findMenuTree(Map<String, Object> param) {
        // TODO Auto-generated method stub
        if (logger.isInfoEnabled()) {
            logger.info("---MenuDAOImpl---findMenuTree");
        }
        return getSqlMapClientTemplate().queryForList("SYS.selectMenuTree", param);
    }
    /* (non-Javadoc)
     * @see com.mttang.sys.integration.dao.MenuDAO#insert(com.mttang.sys.dto.MenuDTO)
     */
    @Override
    public void insert(MenuDTO dto) {
        // TODO Auto-generated method stub
        if (logger.isInfoEnabled()) {
            logger.info("---MenuDAOImpl---insert");
        }
        getSqlMapClientTemplate().insert("SYS.insertMenu", dto);
    }

    /* (non-Javadoc)
     * @see com.mttang.sys.integration.dao.MenuDAO#update(com.mttang.sys.dto.MenuDTO)
     */
    @Override
    public void update(MenuDTO dto) {
        // TODO Auto-generated method stub
        if (logger.isInfoEnabled()) {
            logger.info("---MenuDAOImpl---update");
        }
        getSqlMapClientTemplate().update("SYS.updateMenu", dto);
    }

    /* (non-Javadoc)
     * @see com.mttang.sys.integration.dao.MenuDAO#findMenuLeft(java.lang.Integer)
     */
    @SuppressWarnings("unchecked")
    @Override
    public List<MenuDTO> findMenuLeft(Map<String, Object> param) {
        // TODO Auto-generated method stub
        if (logger.isInfoEnabled()) {
            logger.info("---MenuDAOImpl---findMenuTree");
        }
        if((String.valueOf(param.get("roleId")).split(",").length)>1){
            String[]  ss=String.valueOf(param.get("roleId")).substring(1, String.valueOf(param.get("roleId")).length()-1).split(",");
            param.put("ss", ss);
            }else{
                String[]  ss=String.valueOf(param.get("roleId")).split(",");
                param.put("ss", ss);
            }
        return getSqlMapClientTemplate().queryForList("SYS.selectMenuLeft", param);
    }

    /* (non-Javadoc)
     * @see com.mttang.sys.integration.dao.MenuDAO#findByPid(java.lang.Integer)
     */
    @Override
    public Long findByPid(Integer id) {
        // TODO Auto-generated method stub
        if (logger.isInfoEnabled()) {
            logger.info("---MenuDAOImpl---findByPid");
        }
        return (Long)getSqlMapClientTemplate().queryForObject("SYS.selectMenuByPid", id);
    }
}
